<template>
  <div>
    <PlusPage
      :columns="tableConfig"
      :table="{ adaptive: true, hasIndexColumn: true }"
      :request="getList"
    >
      <!-- 工具栏 -->
      <template #title>
        <el-button type="primary" @click="onExport">导出</el-button>
      </template>
    </PlusPage>
  </div>
</template>

<script lang="ts" setup>
import type { CreditSalesDashboardModel } from '@/api/type'
import { formatEndOfDay, formatStartOfDay } from '@wlydfe/core'
import { omit } from 'lodash-es'
import { companyApi } from '@/api'
import { tableConfig } from './config'

const { getList } = usePage<CreditSalesDashboardModel>({
  fetchData: companyApi.getSaleDashboardList,
  options: {
    transformQuery: query => {
      if (query?.createdDate) {
        const [startDate, endDate] = query.createdDate
        if (startDate && endDate) {
          query.createdDateBegin = formatStartOfDay(startDate)
          query.createdDateEnd = formatEndOfDay(endDate)
          return omit(query, ['createdDate'])
        }
      }
      return query
    },
  },
})

// 导出
const onExport = () => {
  console.log('导出')
}
</script>
